package com.dao.impl;

import com.bean.User;
import com.dao.BaseDao;
import com.dao.UserDao;


/**
 * @author WuLiangHang
 */
public class UserDaoImpl extends BaseDao implements UserDao {
    /**
     * 查询
     * @param username
     * @return
     */
    @Override
    public User queryUserByUsername(String username) {
        String sql = "SELECT `id`, `username`, `password`, `email` FROM user WHERE `username` = ?";
       //调用父类的方法
        return super.queryForOne(User.class, sql, username);

    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public int insertUser(User user) {
//        return null;
        String  sql =  "INSERT INTO user(username,password,email) VALUES (?,?,?)";
        //调用父类的方法
        return super.update(sql,user.getUsername(),user.getPassword(),user.getEmail());

    }

    @Override
    public User queryUserBySelect(User user) {
        String sql = "SELECT `id`, `username`, `password`, `email` FROM user WHERE `username` = ? and `password`=?";
        return super.queryForOne(User.class,sql,user.getUsername(),user.getPassword());
    }


}
